home *** CD-ROM | disk | FTP | other *** search
/ Champak 62 / Volume 62 - JOGO DISK .iso / Games / penguin_dinner.swf / scripts / __Packages / classes / game / Hero.as < prev    next >
Text File  |  2008-03-17  |  3KB  |  124 lines

  1. class classes.game.Hero extends MovieClip
  2. {
  3.    function Hero()
  4.    {
  5.       super();
  6.       this.food = [];
  7.       this.setState(classes.const.Direction.DOWN);
  8.       this.queue = new classes.game.CharActionQueue();
  9.    }
  10.    function giveFood($food)
  11.    {
  12.       var _loc2_ = 0;
  13.       while(_loc2_ < this.food.length)
  14.       {
  15.          if(this.food[_loc2_] == $food)
  16.          {
  17.             this.food.splice(_loc2_,1);
  18.             this.setState();
  19.             return true;
  20.          }
  21.          _loc2_ = _loc2_ + 1;
  22.       }
  23.       return false;
  24.    }
  25.    function takeReadyFood($foodType)
  26.    {
  27.       if($foodType == classes.game.Food.TYPE_NONE || this.food.length == 2)
  28.       {
  29.          return false;
  30.       }
  31.       this.food.push($foodType);
  32.       this.setState();
  33.       return true;
  34.    }
  35.    function clearFood()
  36.    {
  37.       if(this.food.length == 0)
  38.       {
  39.          return undefined;
  40.       }
  41.       classes.core.SoundManager.getInstance().startSound("trashcan");
  42.       this.food = [];
  43.       this.setState();
  44.    }
  45.    function update()
  46.    {
  47.       var _loc2_ = this.queue.getCoords();
  48.       this._x = _loc2_.x;
  49.       this._y = _loc2_.y;
  50.       var _loc5_ = Math.abs(_loc2_.dx);
  51.       var _loc4_ = Math.abs(_loc2_.dy);
  52.       if(_loc5_ + _loc4_ > 0.1)
  53.       {
  54.          var _loc3_ = undefined;
  55.          if(_loc5_ > _loc4_)
  56.          {
  57.             if(_loc2_.dx > 0)
  58.             {
  59.                _loc3_ = classes.const.Direction.RIGHT;
  60.             }
  61.             else
  62.             {
  63.                _loc3_ = classes.const.Direction.LEFT;
  64.             }
  65.          }
  66.          else if(_loc2_.dy > 0)
  67.          {
  68.             _loc3_ = classes.const.Direction.DOWN;
  69.          }
  70.          else
  71.          {
  72.             _loc3_ = classes.const.Direction.UP;
  73.          }
  74.          this.setState(_loc3_);
  75.       }
  76.       this.targetObjReached = _loc2_.end;
  77.    }
  78.    function moveTo(tileX, tileY)
  79.    {
  80.       this.targetTile = new classes.math.Tile(tileX,tileY,0,0,0);
  81.       var _loc2_ = new classes.math.Tile(Math.floor(this._x / classes.math.Tile.SIZE) - classes.math.Tile.DX,Math.floor(this._y / classes.math.Tile.SIZE) - classes.math.Tile.DY,0,0,0);
  82.       this.queue.setTargetTile(_loc2_,this.targetTile,classes.game.GameData.__get__HERO_SPEED());
  83.    }
  84.    function setState($direction)
  85.    {
  86.       if($direction != undefined)
  87.       {
  88.          this.prevDirection = $direction;
  89.       }
  90.       else
  91.       {
  92.          $direction = this.prevDirection;
  93.       }
  94.       var _loc2_ = "walking_";
  95.       switch($direction)
  96.       {
  97.          case classes.const.Direction.UP:
  98.             _loc2_ += "up_";
  99.             break;
  100.          case classes.const.Direction.DOWN:
  101.             _loc2_ += "down_";
  102.             break;
  103.          case classes.const.Direction.RIGHT:
  104.             _loc2_ += "side_";
  105.             this._xscale = 100;
  106.             break;
  107.          case classes.const.Direction.LEFT:
  108.             _loc2_ += "side_";
  109.             this._xscale = -100;
  110.       }
  111.       _loc2_ += String(this.food.length);
  112.       this.gotoAndStop(_loc2_);
  113.       switch(this.food.length)
  114.       {
  115.          case 1:
  116.             this.plate_0.gotoAndStop(this.food[0]);
  117.             break;
  118.          case 2:
  119.             this.plate_0.gotoAndStop(this.food[0]);
  120.             this.plate_1.gotoAndStop(this.food[1]);
  121.       }
  122.    }
  123. }
  124.